<HTML>
<HEAD>
<TITLE>[Chapter 19] GridLayout</TITLE>
<META NAME="author" CONTENT="John Zukowski">
<META NAME="date" CONTENT="Thu Jul 31 15:13:44 1997">
<META NAME="form" CONTENT="html">
<META NAME="metadata" CONTENT="dublincore.0.1">
<META NAME="objecttype" CONTENT="book part">
<META NAME="otheragent" CONTENT="gmat dbtohtml">
<META NAME="publisher" CONTENT="O'Reilly &amp; Associates, Inc.">
<META NAME="source" CONTENT="SGML">
<META NAME="subject" CONTENT="Java AWT">
<META NAME="title" CONTENT="Java AWT">
<META HTTP-EQUIV="Content-Script-Type" CONTENT="text/javascript">
</HEAD>
<body vlink="#551a8b" alink="#ff0000" text="#000000" bgcolor="#FFFFFF" link="#0000ee">

<DIV CLASS=htmlnav>
<H1><a href='index.htm'><IMG SRC="gifs/smbanner.gif"
     ALT="Java AWT" border=0></a></H1>
<table width=515 border=0 cellpadding=0 cellspacing=0>
<tr>
<td width=172 align=left valign=top><A HREF="ch19_29.htm"><IMG SRC="gifs/txtpreva.gif" ALT="Previous" border=0></A></td>
<td width=171 align=center valign=top><B><FONT FACE="ARIEL,HELVETICA,HELV,SANSERIF" SIZE="-1">Chapter 19<br>java.awt Reference</FONT></B></TD>
<td width=172 align=right valign=top><A HREF="ch19_31.htm"><IMG SRC="gifs/txtnexta.gif" ALT="Next" border=0></A></td>
</tr>
</table>

&nbsp;
<hr align=left width=515>
</DIV>
<DIV CLASS=refnamediv>
<H1>GridLayout</H1>

<H2>Name</H2>

GridLayout

</DIV>

<DIV CLASS=refsect1>
<h2 CLASS=refsect1><A CLASS="TITLE" NAME="ch19-REFSECT1-AUTOID.30"></A></h2>
</DIV>


<p>
<img align=middle src="./figs/gridlay.gif" alt="[Graphic: Figure from the text]" width=502 height=77 border=0>

</DIV>

<DIV CLASS=refsect1>
<h2 CLASS=refsect1><A CLASS="TITLE" NAME="JAWT-CH-19-REF-GRIDLAYOUT-SECT-1">Description</A></h2>

<P CLASS=para>
The <tt CLASS=literal>GridLayout</tt> <tt CLASS=literal>LayoutManager</tt> 
provides the means to layout components in a grid of rows and columns. 

</DIV>

<DIV CLASS=refsect1>
<h2 CLASS=refsect1><A CLASS="TITLE" NAME="JAWT-CH-19-REF-GRIDLAYOUT-SECT-2">Class Definition</A></h2>

<DIV CLASS=screen>
<P>
<PRE>
public class java.awt.GridLayout
        extends java.lang.Object
        implements java.awt.LayoutManager, java.io.Serializable
 {
  
// Constructors
  public GridLayout(); <img src="gifs/bstar.gif" alt="(New)" border=0>
  public GridLayout (int rows, int cols);
  public GridLayout (int rows, int cols, int hgap, int vgap);
  
// Instance Methods
  public void addLayoutComponent (String name, Component component);
  public int getColumns(); <img src="gifs/bstar.gif" alt="(New)" border=0>
  public int getHgap(); <img src="gifs/bstar.gif" alt="(New)" border=0>
  public int getRows(); <img src="gifs/bstar.gif" alt="(New)" border=0>
 
  public int getVgap(); <img src="gifs/bstar.gif" alt="(New)" border=0>
  public void layoutContainer (Container target); 
  public Dimension minimumLayoutSize (Container target); 
  public Dimension preferredLayoutSize (Container target); 
  public void removeLayoutComponent (Component component); 
  public int setColumns(int cols); <img src="gifs/bstar.gif" alt="(New)" border=0>
  public int setHgap(int hgap); <img src="gifs/bstar.gif" alt="(New)" border=0>
  public int setRows(int rows); <img src="gifs/bstar.gif" alt="(New)" border=0>
 
  public int setVgap(int vgap); <img src="gifs/bstar.gif" alt="(New)" border=0>
  public String toString();
}
</PRE>
</DIV>

</DIV>

<DIV CLASS=refsect1>
<h2 CLASS=refsect1><A CLASS="TITLE" NAME="JAWT-CH-19-REF-GRIDLAYOUT-SECT-3">Constructors</A></h2>

<DIV CLASS=refsect2>
<h3 CLASS=refsect2><A CLASS="TITLE" NAME="JAWT-CH-19-REF-GRIDLAYOUT-SECT-3.1">GridLayout</A></h3>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="JAWT-CH-19-REF-GRIDLAYOUT-SECT-3.1.1">public GridLayout() <img src="gifs/bstar.gif" alt="(New)" border=0></A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Description<br>
<DD>

<P CLASS=para>
Constructs a <tt CLASS=literal>GridLayout</tt> object 
with a default single row and one column per component. </DL>
</DIV>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="JAWT-CH-19-REF-GRIDLAYOUT-SECT-3.1.2">public GridLayout (int rows, int cols)</A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Parameters<br>
<DD>

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><I CLASS=emphasis>rows</I><br>
<DD>

<P CLASS=para>
Requested number of rows in container. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>cols</I><br>
<DD>

<P CLASS=para>
Requested number of columns in container. </DL>
<p>
<DT CLASS=varlistentry>Description<br>
<DD>

<P CLASS=para>
Constructs a <tt CLASS=literal>GridLayout</tt> object 
with the requested number of rows and columns. Note that the actual number 
of rows and columns depends on the number of objects in the layout, not 
the constructor's parameters. </DL>
</DIV>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="JAWT-CH-19-REF-GRIDLAYOUT-SECT-3.1.3">public GridLayout (int rows, int cols, int hgap, int vgap)</A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Parameters<br>
<DD>

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><I CLASS=emphasis>rows</I><br>
<DD>

<P CLASS=para>
Requested number of rows in container. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>cols</I><br>
<DD>

<P CLASS=para>
Requested number of columns in container. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>hgap</I><br>
<DD>

<P CLASS=para>
Horizontal space between each component in a row. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>vgap</I><br>
<DD>

<P CLASS=para>
Vertical space between each row. </DL>
<p>
<DT CLASS=varlistentry>Description<br>
<DD>

<P CLASS=para>
Constructs a <tt CLASS=literal>GridLayout</tt> object 
with the requested number of <tt CLASS=literal>rows</tt> 
and <tt CLASS=literal>columns</tt> and the values 
specified as the gaps between each component. Note that the actual number 
of rows and columns depends on the number of objects in the layout, not 
the constructor's parameters. </DL>
</DIV>

</DIV>

</DIV>

<DIV CLASS=refsect1>
<h2 CLASS=refsect1><A CLASS="TITLE" NAME="JAWT-CH-19-REF-GRIDLAYOUT-SECT-4">Instance Methods</A></h2>

<DIV CLASS=refsect2>
<h3 CLASS=refsect2><A CLASS="TITLE" NAME="JAWT-CH-19-REF-GRIDLAYOUT-SECT-4.1">addLayoutComponent</A></h3>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="JAWT-CH-19-REF-GRIDLAYOUT-SECT-4.1.1">public void addLayoutComponent (String name, Component component)</A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Parameters<br>
<DD>

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><I CLASS=emphasis>name</I><br>
<DD>

<P CLASS=para>
Name of component to 
add. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>component</I><br>
<DD>

<P CLASS=para>
Actual component 
being added. </DL>
<p>
<DT CLASS=varlistentry>Implements <br>
<DD>

<P CLASS=para>
<tt CLASS=literal>LayoutManager.addLayoutComponent()</tt> 

<p>
<DT CLASS=varlistentry>Description<br>
<DD>

<P CLASS=para>
Does nothing. </DL>
</DIV>

</DIV>

<DIV CLASS=refsect2>
<h3 CLASS=refsect2><A CLASS="TITLE" NAME="JAWT-CH-19-REF-GRIDLAYOUT-SECT-4.2">getColumns</A></h3>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="JAWT-CH-19-REF-GRIDLAYOUT-SECT-4.2.1">public int getColumns() <img src="gifs/bstar.gif" alt="(New)" border=0></A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Returns<br>
<DD>

<P CLASS=para>
The number of columns. </DL>
</DIV>

</DIV>

<DIV CLASS=refsect2>
<h3 CLASS=refsect2><A CLASS="TITLE" NAME="JAWT-CH-19-REF-GRIDLAYOUT-SECT-4.3">getHgap</A></h3>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="JAWT-CH-19-REF-GRIDLAYOUT-SECT-4.3.1">public int getHgap() <img src="gifs/bstar.gif" alt="(New)" border=0></A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Returns<br>
<DD>

<P CLASS=para>
The horizontal gap for this <tt CLASS=literal>GridLayout</tt> 
instance. </DL>
</DIV>

</DIV>

<DIV CLASS=refsect2>
<h3 CLASS=refsect2><A CLASS="TITLE" NAME="JAWT-CH-19-REF-GRIDLAYOUT-SECT-4.4">getRows</A></h3>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="JAWT-CH-19-REF-GRIDLAYOUT-SECT-4.4.1">public int getRows() <img src="gifs/bstar.gif" alt="(New)" border=0></A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Returns<br>
<DD>

<P CLASS=para>
The number of rows. </DL>
</DIV>

</DIV>

<DIV CLASS=refsect2>
<h3 CLASS=refsect2><A CLASS="TITLE" NAME="JAWT-CH-19-REF-GRIDLAYOUT-SECT-4.5">getVgap</A></h3>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="JAWT-CH-19-REF-GRIDLAYOUT-SECT-4.5.1">public int getVgap() <img src="gifs/bstar.gif" alt="(New)" border=0></A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Returns<br>
<DD>

<P CLASS=para>
The vertical gap for this <tt CLASS=literal>GridLayout</tt> 
instance. </DL>
</DIV>

</DIV>

<DIV CLASS=refsect2>
<h3 CLASS=refsect2><A CLASS="TITLE" NAME="JAWT-CH-19-REF-GRIDLAYOUT-SECT-4.6">layoutContainer</A></h3>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="JAWT-CH-19-REF-GRIDLAYOUT-SECT-4.6.1">public void layoutContainer (Container target)</A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Parameters<br>
<DD>

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><I CLASS=emphasis>target</I><br>
<DD>

<P CLASS=para>
The container that needs to be redrawn. </DL>
<p>
<DT CLASS=varlistentry>Implements <br>
<DD>

<P CLASS=para>
<tt CLASS=literal>LayoutManager.layoutContainer()</tt> 

<p>
<DT CLASS=varlistentry>Description<br>
<DD>

<P CLASS=para>
Draws the components contained within the <tt CLASS=literal>target</tt>. </DL>
</DIV>

</DIV>

<DIV CLASS=refsect2>
<h3 CLASS=refsect2><A CLASS="TITLE" NAME="JAWT-CH-19-REF-GRIDLAYOUT-SECT-4.7">minimumLayoutSize</A></h3>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="JAWT-CH-19-REF-GRIDLAYOUT-SECT-4.7.1">public Dimension minimumLayoutSize (Container target)</A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Parameters<br>
<DD>

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><I CLASS=emphasis>target</I><br>
<DD>

<P CLASS=para>
The container whose 
size needs to be calculated. </DL>
<p>
<DT CLASS=varlistentry>Returns<br>
<DD>

<P CLASS=para>
Minimum <tt CLASS=literal>Dimension</tt> of the container 
<tt CLASS=literal>target</tt>. 

<p>
<DT CLASS=varlistentry>Implements <br>
<DD>

<P CLASS=para>
<tt CLASS=literal>LayoutManager.minimumLayoutSize()</tt> 

<p>
<DT CLASS=varlistentry>Description<br>
<DD>

<P CLASS=para>
Calculates the minimum size of the <tt CLASS=literal>target</tt> 
container. </DL>
</DIV>

</DIV>

<DIV CLASS=refsect2>
<h3 CLASS=refsect2><A CLASS="TITLE" NAME="JAWT-CH-19-REF-GRIDLAYOUT-SECT-4.8">preferredLayoutSize</A></h3>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="JAWT-CH-19-REF-GRIDLAYOUT-SECT-4.8.1">public Dimension preferredLayoutSize (Container target)</A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Parameters<br>
<DD>

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><I CLASS=emphasis>target</I><br>
<DD>

<P CLASS=para>
The container whose 
size needs to be calculated. </DL>
<p>
<DT CLASS=varlistentry>Returns<br>
<DD>

<P CLASS=para>
Preferred <tt CLASS=literal>Dimension</tt> of the 
container <tt CLASS=literal>target</tt>. 

<p>
<DT CLASS=varlistentry>Implements <br>
<DD>

<P CLASS=para>
<tt CLASS=literal>LayoutManager.preferredLayoutSize()</tt> 

<p>
<DT CLASS=varlistentry>Description<br>
<DD>

<P CLASS=para>
Calculates the preferred size of the <tt CLASS=literal>target</tt> 
container. </DL>
</DIV>

</DIV>

<DIV CLASS=refsect2>
<h3 CLASS=refsect2><A CLASS="TITLE" NAME="JAWT-CH-19-REF-GRIDLAYOUT-SECT-4.9">removeLayoutComponent</A></h3>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="JAWT-CH-19-REF-GRIDLAYOUT-SECT-4.9.1">public void removeLayoutComponent (Component component)</A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Parameters<br>
<DD>

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><I CLASS=emphasis>component</I><br>
<DD>

<P CLASS=para>
Component to stop tracking. </DL>
<p>
<DT CLASS=varlistentry>Implements <br>
<DD>

<P CLASS=para>
<tt CLASS=literal>LayoutManager.removeLayoutComponent()</tt> 

<p>
<DT CLASS=varlistentry>Description<br>
<DD>

<P CLASS=para>
Does nothing. </DL>
</DIV>

</DIV>

<DIV CLASS=refsect2>
<h3 CLASS=refsect2><A CLASS="TITLE" NAME="JAWT-CH-19-REF-GRIDLAYOUT-SECT-4.10">setColumns</A></h3>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="JAWT-CH-19-REF-GRIDLAYOUT-SECT-4.10.1">public void setColumns(int cols) <img src="gifs/bstar.gif" alt="(New)" border=0></A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Parameters<br>
<DD>

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><I CLASS=emphasis>cols</I><br>
<DD>

<P CLASS=para>
The new number of columns. </DL>
<p>
<DT CLASS=varlistentry>Description<br>
<DD>

<P CLASS=para>
Sets the number of columns. </DL>
</DIV>

</DIV>

<DIV CLASS=refsect2>
<h3 CLASS=refsect2><A CLASS="TITLE" NAME="JAWT-CH-19-REF-GRIDLAYOUT-SECT-4.11">setHgap</A></h3>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="JAWT-CH-19-REF-GRIDLAYOUT-SECT-4.11.1">public void setHgap(int hgap) <img src="gifs/bstar.gif" alt="(New)" border=0></A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Parameters<br>
<DD>

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><I CLASS=emphasis>hgap</I><br>
<DD>

<P CLASS=para>
The horizontal gap value. </DL>
<p>
<DT CLASS=varlistentry>Description<br>
<DD>

<P CLASS=para>
Sets the horizontal gap between components. </DL>
</DIV>

</DIV>

<DIV CLASS=refsect2>
<h3 CLASS=refsect2><A CLASS="TITLE" NAME="JAWT-CH-19-REF-GRIDLAYOUT-SECT-4.12">setRows</A></h3>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="JAWT-CH-19-REF-GRIDLAYOUT-SECT-4.12.1">public void setRows(int rows) <img src="gifs/bstar.gif" alt="(New)" border=0></A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Parameters<br>
<DD>

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><I CLASS=emphasis>rows</I><br>
<DD>

<P CLASS=para>
The new number of rows. </DL>
<p>
<DT CLASS=varlistentry>Description<br>
<DD>

<P CLASS=para>
Sets the number of rows. </DL>
</DIV>

</DIV>

<DIV CLASS=refsect2>
<h3 CLASS=refsect2><A CLASS="TITLE" NAME="JAWT-CH-19-REF-GRIDLAYOUT-SECT-4.13">setVgap</A></h3>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="JAWT-CH-19-REF-GRIDLAYOUT-SECT-4.13.1">public void setVgap(int vgap) <img src="gifs/bstar.gif" alt="(New)" border=0></A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Parameters<br>
<DD>

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><I CLASS=emphasis>vgap</I><br>
<DD>

<P CLASS=para>
The vertical gap value. </DL>
<p>
<DT CLASS=varlistentry>Description<br>
<DD>

<P CLASS=para>
Sets the vertical gap between components. </DL>
</DIV>

</DIV>

<DIV CLASS=refsect2>
<h3 CLASS=refsect2><A CLASS="TITLE" NAME="JAWT-CH-19-REF-GRIDLAYOUT-SECT-4.14">toString</A></h3>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="JAWT-CH-19-REF-GRIDLAYOUT-SECT-4.14.1">public String toString()</A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Returns<br>
<DD>

<P CLASS=para>
A string representation of the <tt CLASS=literal>GridLayout</tt> 
object. 

<p>
<DT CLASS=varlistentry>Overrides <br>
<DD>

<P CLASS=para>
<tt CLASS=literal>Object.toString()</tt> </DL>
</DIV>

</DIV>

</DIV>

<DIV CLASS=refsect1>
<h2 CLASS=refsect1><A CLASS="TITLE" NAME="JAWT-CH-19-REF-GRIDLAYOUT-SECT-5">See Also</A></h2>

<P CLASS=para>
<tt CLASS=literal>Component</tt>, <tt CLASS=literal>Container</tt>, 
<tt CLASS=literal>Dimension</tt>, <tt CLASS=literal>LayoutManager</tt>, 
<tt CLASS=literal>Object</tt>, <tt CLASS=literal>String</tt> 

</DIV>


<DIV CLASS=htmlnav>

<P>
<HR align=left width=515>
<table width=515 border=0 cellpadding=0 cellspacing=0>
<tr>
<td width=172 align=left valign=top><A HREF="ch19_29.htm"><IMG SRC="gifs/txtpreva.gif" ALT="Previous" border=0></A></td>
<td width=171 align=center valign=top><a href="index.htm"><img src='gifs/txthome.gif' border=0 alt='Home'></a></td>
<td width=172 align=right valign=top><A HREF="ch19_31.htm"><IMG SRC="gifs/txtnexta.gif" ALT="Next" border=0></A></td>
</tr>
<tr>
<td width=172 align=left valign=top>GridBagLayout</td>
<td width=171 align=center valign=top><a href="index/idx_a.htm"><img src='gifs/index.gif' alt='Book Index' border=0></a></td>
<td width=172 align=right valign=top>IllegalComponentStateException <img src="gifs/bstar.gif" alt="(New)" border=0></td>
</tr>
</table>
<hr align=left width=515>

<IMG SRC="gifs/smnavbar.gif" USEMAP="#map" BORDER=0> 
<MAP NAME="map"> 
<AREA SHAPE=RECT COORDS="0,0,108,15" HREF="../javanut/index.htm"
alt="Java in a Nutshell"> 
<AREA SHAPE=RECT COORDS="109,0,200,15" HREF="../langref/index.htm" 
alt="Java Language Reference"> 
<AREA SHAPE=RECT COORDS="203,0,290,15" HREF="../awt/index.htm" 
alt="Java AWT"> 
<AREA SHAPE=RECT COORDS="291,0,419,15" HREF="../fclass/index.htm" 
alt="Java Fundamental Classes"> 
<AREA SHAPE=RECT COORDS="421,0,514,15" HREF="../exp/index.htm" 
alt="Exploring Java"> 
</MAP>
</DIV>

</BODY>
</HTML>
